<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="root">
    <!--<h2 style="opacity: 1">欢迎学习vue</h2>-->
    <h2 :style="{opacity}">欢迎学习vue</h2>
    <button @click="stop()">点击停止变换</button>
    <button @click="opacity=1">点击透明为1</button>
</div>
<script src="../js/vue.js"></script>
<script>
    Vue.config.productionTip = false//阻止vue启动时产生提示
    new Vue({
        el: "#root",
        data: {//数据
            name: '',
            opacity: 1
        },
        methods: {//方法
            stop(){
                this.$destroy()
                /*clearInterval(this.timer)*/
            }
        },
        computed: {//计算

        },
        watch: {//监视

        },
        //vue完成模板的解析并且把初始的真实的DOM元素放入页面后调用mounted(挂载完毕)
        mounted() {//挂载
            this.timer=setInterval(() => {
                console.log('Interval')
                this.opacity -= 0.01
                if (this.opacity <= 0) this.opacity = 1;
            }, 16)
        },
        beforeDestroy() {
            console.log("即将驾鹤西去")
            clearInterval(this.timer)
        }
    })
</script>
</body>
</html>